// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
int n,m,a,b;
vector<int> v[100001];
vector<bool> f;
void dfs(int x)
{
	cout<<x<<" ";
	for(int i=0;i<v[x].size();i++)
	{
		if(!f[v[x][i]])
		{
			f[v[x][i]]=1;
			dfs(v[x][i]);
		}
	}
}
signed main()
{
	cin>>n>>m;
	f=vector<bool>(n+1);
	for(int i=1;i<=m;i++)
	{
		cin>>a>>b;
		v[a].push_back(b);
	}
	for(int i=1;i<=n;i++)
	{
		sort(v[i].begin(),v[i].end());
	}
	f[1]=1;
	dfs(1);
	cout<<endl;
	f=vector<bool>(n+1);
	f[1]=1;
	queue<int> q;
	q.push(1);
	while(!q.empty())
	{
		int tmp=q.front();
		cout<<tmp<<" ";
		q.pop();
		for(int i=0;i<v[tmp].size();i++)
		{
			if(!f[v[tmp][i]])
			{
				f[v[tmp][i]]=1;
				q.push(v[tmp][i]);
			}
		}
	}
	return 0;
}
